870A - Search for Pretty Integers - CodeForces Solution


brute force implementation *900

Please click on ads to support us..

Python Code:

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a1=min(a)
b1=min(b)

a2=set(a)
b2=set(b)
c=a2 & b2
if len(c)>0:
    print(min(c))
    quit()
print(min(a1,b1)*10+max(a1,b1))

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,ans=INT_MAX;
    cin >> n >> m;
    int a[n+2];
    int b[m+2];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i]==b[j]){
                ans=min(ans,a[i]);
            }
            else{
                ans=min(ans,a[i]*10+b[j]);
                ans=min(ans,b[j]*10+a[i]);
            }
        }
    }
    cout << ans;
    return 0;
}


Comments

Submit
0 Comments
More Questions

409H - A + B Strikes Back
1262A - Math Problem
158C - Cd and pwd commands
194A - Exams
1673B - A Perfectly Balanced String
1104B - Game with string
1169B - Pairs
1567D - Expression Evaluation Error
78A - Haiku
1287A - Angry Students
1428A - Box is Pull
234B - Reading
581B - Luxurious Houses
1481C - Fence Painting
935A - Fafa and his Company
22A - Second Order Statistics
1720B - Interesting Sum
1720A - Burenka Plays with Fractions
3A - Shortest path of the king
1720C - Corners
574A - Bear and Elections
352B - Jeff and Periods
1244A - Pens and Pencils
1670A - Prof Slim
1189A - Keanu Reeves
678A - Johny Likes Numbers
1699C - The Third Problem
1697D - Guess The String
754B - Ilya and tic-tac-toe game
760A - Petr and a calendar